package com.hcf.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hcf.admin.common.biz.user.UserContext;
import com.hcf.admin.common.convention.result.Result;
import com.hcf.admin.dao.entity.GroupDO;
import com.hcf.admin.dao.mapper.GroupMapper;
import com.hcf.admin.remote.ShortLinkProjectService;
import com.hcf.admin.remote.dto.req.RecycleBinPageReqDTO;
import com.hcf.admin.remote.dto.resp.ShortLinkPageRespDTO;
import com.hcf.admin.service.RecycleBinService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RecycleBinServiceImpl extends ServiceImpl<GroupMapper, GroupDO> implements RecycleBinService {

    ShortLinkProjectService shortLinkProjectService = new ShortLinkProjectService(){};
    @Override
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink() {
        // 根据用户查询gidList
        LambdaQueryWrapper<GroupDO> eq = Wrappers.lambdaQuery(GroupDO.class)
                .eq(GroupDO::getUsername, UserContext.getUsername());
        List<GroupDO> groupDOs = baseMapper.selectList(eq);
        List<String> gidList = groupDOs.stream().map(GroupDO::getGid).collect(Collectors.toList());
        RecycleBinPageReqDTO requestParam = new RecycleBinPageReqDTO();
        requestParam.setGidList(gidList);
        return shortLinkProjectService.pageRecycleBin(requestParam);
    }
}
